import { _decorator, animation, Animation } from "cc";
import { Entity } from "../Entity";
import { DirectionNames } from "../../enums/Direction";
import { CocosUtils } from "../../utils/CocosUtils";
import { eventDispatcher } from "../../Constants";
import { EventType } from "../../enums/EventType";
import { AnimatorParam } from "../../enums/AnimatorParam";
const { ccclass } = _decorator;

@ccclass("SmokeIdleState")
export class SmokeIdleState extends animation.StateMachineComponent {

    public async onMotionStateEnter(controller: animation.AnimationController, motionStateStatus: Readonly<animation.MotionStateStatus>): Promise<void> {
        controller.setValue(AnimatorParam.STATE, Entity.State.DEATH);

        const entity = controller.getComponent(Entity);
        const animation = controller.getComponentInChildren(Animation);
        const direction = entity.direction;
        const entityName = entity.name;
        const animName = `${entityName}/idle/${DirectionNames[direction]}`;
        const atlasPath = `texture/${entityName}/idle/${DirectionNames[direction]}/idle`;
        await CocosUtils.playAnimation(animation, animName, atlasPath);
        eventDispatcher.emit(EventType.RECYLE_SMOKE, controller.node);
    }
}